package com.bilibili.juc.cf;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import static org.junit.Assert.assertTrue;

public class CompletableFutureAllofDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<String> future1
                = CompletableFuture.supplyAsync(() -> "Hello");
        CompletableFuture<String> future2
                = CompletableFuture.supplyAsync(() -> "Beautiful");
        CompletableFuture<String> future3
                = CompletableFuture.supplyAsync(() -> "World");

        CompletableFuture<Void> allOfFuture
                = CompletableFuture.allOf(future1, future2, future3);


// ...

        System.out.println("allOf value==>> " + allOfFuture.get());
        assertTrue(future1.isDone());
        assertTrue(future2.isDone());
        assertTrue(future3.isDone());
        System.out.println("future1==>> " + future1.get());
        System.out.println("future2==>> " + future2.get());
        System.out.println("future3==>> " + future3.get());
    }
}
